package cn.youth996.nav.controller;

import cn.youth996.nav.service.OsrmService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

/**
 * 路径规划controller
 *
 * @author Zhan Xinjian
 * @date 2025/5/12
 */
@RestController
@RequestMapping("/direction")
public class DirectionController {
    @Autowired
    private OsrmService osrmService;


    /**
     * 模拟腾讯地图的路径规划接口
     * 示例: /direction?from=31.23,121.47&to=31.25,121.50
     */
    @GetMapping
    public ResponseEntity<?> getRoute(@RequestParam String from, @RequestParam String to) {
        try {
            String result = osrmService.getRoute(from, to);
            return ResponseEntity.ok(result);
        } catch (Exception e) {
            return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR)
                    .body(Map.of("error", e.getMessage()));
        }
    }
}
